package com.shop.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shop.po.Message;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author banxia
 * @since 2023-02-24
 */
@Mapper
public interface MessageMapper extends BaseMapper<Message> {

    @Select("SELECT t.* FROM message t WHERE t.id % #{shardTotal} = #{shardindex} and t.state='0' and t.message_type=#{messageType} limit #{count}")
    List<Message> selectListByShardIndex(@Param("shardTotal") int shardTotal,
                                         @Param("shardindex") int shardindex,
                                         @Param("messageType") String messageType,
                                         @Param("count") int count);

    //得到的sql还需要达到“已发布时间”
    @Select("SELECT t.* FROM message t WHERE t.id % #{shardTotal} = #{shardIndex} and t.state='0' and t.message_type=#{messageType} " +
            "and business_key2 <= #{now} limit #{count}")
    List<Message> discountPublishMessage(@Param("shardIndex") int shardIndex,
                                         @Param("shardTotal") int shardTotal,
                                         @Param("messageType") String messageType,
                                         @Param("count") int count,
                                         @Param("now") String now);
}
